// 创建http服务
const http = require('http')
// 引入fs
const fs = require('fs')
const { Socket } = require('socket.io')
// 创建服务
const app = http .createServer()


// 监听端口
app.on('request', (req, res) => {
  fs.readFile(__dirname + './index.html', function(err, data) {
    res.writeHead(200)
    res.end(data)
  })
})

app.listen(3000, () => {
  console.log('启动成功！')
})

// 引入socket.io
const io = require('socket.io')(app)

io.on('connection', Socket => {
  console.log('用户链接')
})